<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Postfilters</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="advanced.features.html" title="Chapter 17. Advanced Features">
<link rel="prev" href="advanced.features.prefilters.html" title="Prefilters">
<link rel="next" href="advanced.features.outputfilters.html" title="Output Filters">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Postfilters</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="advanced.features.prefilters.html">Prev</a> </td>
<th width="60%" align="center">Chapter 17. Advanced Features</th>
<td width="20%" align="right"> <a accesskey="n" href="advanced.features.outputfilters.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Postfilters">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="advanced.features.postfilters"></a>Postfilters</h2></div></div></div>
<p>
  Template postfilters are PHP functions that your templates are ran through
  <span class="emphasis"><em>after they are compiled</em></span>. Postfilters can be either
  <a class="link" href="api.register.filter.html" title="registerFilter()">registered</a> or loaded
  from the <a class="link" href="variable.plugins.dir.html" title="$plugins_dir">plugins directory</a>
  by using the
  <a class="link" href="api.load.filter.html" title="loadFilter()"><code class="varname">loadFilter()</code></a>
   function or by setting the <a class="link" href="variable.autoload.filters.html" title="$autoload_filters">
   <em class="parameter"><code>$autoload_filters</code></em></a> variable.
   Smarty will pass the compiled template code as the first
  argument, and expect the function to return the result of the
  processing.
 </p>
<div class="example">
<a name="id460627"></a><p class="title"><b>Example 17.12. Using a template postfilter</b></p>
<div class="example-contents">
<pre class="programlisting">

&lt;?php
// put this in your application
function add_header_comment($tpl_source, Smarty_Internal_Template $template)
{
    return "&lt;?php echo \"&lt;!-- Created by Smarty! --&gt;\n\"; ?&gt;\n".$tpl_source;
}

// register the postfilter
$smarty-&gt;registerFilter('post','add_header_comment');
$smarty-&gt;display('index.tpl');
?&gt;

  </pre>
<p>
   The postfilter above will make the compiled Smarty template
   <code class="filename">index.tpl</code> look like:
  </p>
<pre class="screen">

&lt;!-- Created by Smarty! --&gt;
{* rest of template content... *}

  </pre>
</div>
</div>
<br class="example-break"><p>
 See also
 <a class="link" href="api.register.filter.html" title="registerFilter()"><code class="varname">registerFilter()</code></a>,
 <a class="link" href="advanced.features.prefilters.html" title="Prefilters">prefilters</a>,
 <a class="link" href="advanced.features.outputfilters.html" title="Output Filters">outputfilters</a>,
 and
 <a class="link" href="api.load.filter.html" title="loadFilter()"><code class="varname">loadFilter()</code></a>.
 </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="advanced.features.prefilters.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="advanced.features.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="advanced.features.outputfilters.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Prefilters </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Output Filters</td>
</tr>
</table>
</div>
</body>
</html>
